﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARControlLib
{
	/// <summary>
	/// SARButtonUpdate.xaml 的交互逻辑
	/// </summary>
	public partial class SARButtonUpdate : UserControl
	{
		public SARButtonUpdate()
		{
			this.InitializeComponent();
		}

		

        private string windowsTxt;

        /// <summary>
        /// 按钮上显示的文本
        /// </summary>
        public string SARWindowsText
        {
            get
            {
                windowsTxt = this.TextFiled.Text;
                return windowsTxt;
            }
            set
            {
                windowsTxt = value;
                this.TextFiled.Text = windowsTxt;
            }
        }
		
        /// <summary>
        /// 按钮被单击事件
        /// </summary>
        public event MouseButtonEventHandler SARBtnUpdateClick;
		
		private void UserControl_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
		{
			// 在此处添加事件处理程序实现。

            if (!isEnabled)
            {
                return;
            }

            this.TextFiled.Margin = new Thickness(33, 5, 0, 0);
		}
		
		
        private bool isEnabled = true;

        /// <summary>
        /// 按钮是否处于启用状态
        /// </summary>
        public bool SARIsEnabled
        {
            set
            {
                isEnabled = value;
                if (isEnabled)
                {
                    this.Opacity = 1;
                }
                else
                {
                    this.Opacity = 0.5;
                }
            }
            get
            {
                return isEnabled;
            }
        }


		private void UserControl_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			// 在此处添加事件处理程序实现。
			
            if (!isEnabled)
            {
                return;
            }

            this.TextFiled.Margin = new Thickness(34, 6, 0, 0);

            if (SARBtnUpdateClick != null)
            {
                SARBtnUpdateClick.Invoke(this, e);
            }
		}

		private void UserControl_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			// 在此处添加事件处理程序实现。

            if (!isEnabled)
            {
                return;
            }

            this.TextFiled.Margin = new Thickness(33, 5, 0, 0);
		}
	}
}